package com.movecar.ui;

import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

import com.movecar.R;
import com.movecar.utils.AppConfig;
import com.movecar.utils.DataStore;
import com.tencent.tauth.Tencent;

/**
 * 启动页面
 * 
 * @author Zhao.JQ
 * 
 */

public class StartActivity extends Activity {
	private String alias;
	private Set<String> tags;
	private int a;
	TagAliasCallback callback;
	Tencent mTencent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start_activity);
		mTencent = Tencent.createInstance(AppConfig.QQ_LOGIN_APPID, StartActivity.this);
		initApp();
	}

	private void initApp() {
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				SharedPreferences sharedPreferences = getSharedPreferences("login", Context.MODE_PRIVATE);
				//
				String userId = sharedPreferences.getString("userId", "");
				String mobile = sharedPreferences.getString("mobile", "");
				if (!"".equals(userId) && !"".equals(mobile)) {
					DataStore.getInstance().setMobile(mobile);
					DataStore.getInstance().setUserId(userId);
					if (TextUtils.isEmpty(DataStore.getInstance().getNickName())) {
						DataStore.getInstance().setNickName(mobile);
					}

					JPushInterface.setAliasAndTags(StartActivity.this, DataStore.getInstance().getMobile(), null,
							callback);
					startActivity(MainActivity.class, true);

				} else {
					startActivity(WelcomeActivity.class, true);
				}

			}
		}, 2000);
	}

	protected void startActivity(Class<?> toActivity, boolean finish) {
		Intent intent = new Intent(this, toActivity);
		startActivity(intent);
		if (finish) {
			finish();
		}
	}

}
